package com.alittle.core;

import android.os.Bundle;

import com.alittle.support.support.mvp.MvpPresenter;
import com.alittle.support.support.mvp.MvpView;

/**
 * Created by wom on 15-4-29.
 */
public abstract class ALBaseMvpActivity<P extends MvpPresenter> extends ALBaseActivity implements MvpView {

    protected P presenter;

    protected abstract P createPresenter();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presenter = createPresenter();
        if (presenter == null) {
            throw new NullPointerException("Presenter is null! Do you return null in createPresenter()?");
        }
        presenter.attachView(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.detachView(false);
    }

}